<template>
  <div>
    <van-cell class="comment-item">
      <van-image
        slot="icon"
        class="avatar"
        round
        fit="cover"
        :src="comItem.aut_photo"
      />
      <div slot="title" class="title-wrap">
        <div class="user-name">{{ comItem.aut_name }}</div>
        <van-button
          class="like-btn"
          icon="good-job"
          :class="{ likeing: comItem.is_liking }"
          @click="likeFn"
        >
          {{ comItem.like_count || "赞" }}
        </van-button>
      </div>

      <div slot="label">
        <p class="comment-content">{{ comItem.content }}</p>
        <div class="bottom-info">
          <span class="comment-pubdate">{{ comItem.pubdate | datatime }}</span>
          <van-button class="reply-btn" round @click="replyFn">
            回复 {{ comItem.reply_count }}</van-button
          >
        </div>
      </div>
    </van-cell>
  </div>
</template>

<script>
import { likeingGoApi, likeingOutApi } from "@/api/comment";
export default {
  name: "CommentItem",
  components: {},
  props: {
    comItem: Object,
  },
  data() {
    return {};
  },
  methods: {
    async likeFn() {
      try {
        if (this.comItem.is_liking) {
          //取消点赞接口
          await likeingGoApi(this.comItem.com_id);
          //手动修改视图
          this.comItem.like_count--;
        } else {
          //点赞接口
          await likeingOutApi(this.comItem.com_id);
          //手动修改视图
          this.comItem.like_count++;
        }
        ///修改用户点赞的状态n
        this.comItem.is_liking = !this.comItem.is_liking;
      } catch (error) {
        console.log(error);
      }
    },
    replyFn() {
      //打开评论回复详情弹层
      //item-》list->详情
      this.$emit("replyFn", this.comItem);
    },
  },
};
</script>

<style scoped lang="less">
.comment-item {
  .avatar {
    width: 72px;
    height: 72px;
    margin-right: 25px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 26px;
    }
  }
  .comment-content {
    font-size: 32px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 19px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
    margin-top: 20px;
  }
  .reply-btn {
    width: 135px;
    height: 48px;
    line-height: 48px;
    font-size: 21px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }
  }
  .likeing {
    color: #e5645f;
  }
}
</style>
